<?php

App::uses('AppRule', 'Lib');

class BookInAdvance extends AppRule {
    
    public $arguments = array(
    	'days' => 'int'
    );

    public function apply(Leave $leave, $days=0) {
        $ret  = true;
        $data = $leave->data['Leave'];
        
        $now   = strtotime(date('Y-m-d'));
        $start = strtotime($data['start']);
        if (($start-$now) < $days * DAY) {
            $ret = false;
            $this->setError("You need to request leave at least {$days} before.");
        }
        
        return $ret;
    }

}

?>